var t = require("../../../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Component({
    properties: {
        show: {
            type: Boolean
        },
        showCategory: {
            type: Boolean
        }
    },
    data: {
        goodScreenAll: [],
        screentitle: [ "品牌", "分类", "属性", "高级选项" ],
        showPop: !1,
        show1: !0,
        show2: !1,
        show3: !1,
        show4: !1,
        select: "",
        brand: [],
        attr: [ {
            name: "推荐商品",
            rot: "is_recommand",
            show: !0
        }, {
            name: "新品上市",
            rot: "is_new",
            show: !0
        }, {
            name: "热卖商品",
            rot: "is_hot",
            show: !0
        }, {
            name: "促销商品",
            rot: "is_discount",
            show: !0
        }, {
            name: "限时抢购",
            rot: "limit_buy",
            show: !0
        } ],
        attrstr: [],
        attrkey: [],
        classification1: [],
        classification2: [],
        classificationId: null,
        classificationId1: null,
        classificationId2: null,
        classificationParentIndex: 0,
        tagname: [],
        showtagnamekey: null,
        typestring: "",
        filterId: [],
        brandId: "",
        classShowind: "",
        classShowName: "",
        top: "",
        mini: ""
    },
    observers: {
        show: function(t) {
            this.setData({
                showPop: t
            }), t && (0 == this.data.brand.length && this.getbrand(), 0 == this.data.classification1.length && this.getclassification(), 
            0 == this.data.tagname.length && this.getname());
        }
    },
    methods: {
        getbrand: function() {
            var t = this, s = a.getNetAddresss("goods.brand.get-brand");
            a._postNetWork({
                url: s,
                showToastIn: !1,
                success: function(a) {
                    var s = a.data;
                    1 == s.result && t.setData({
                        brand: s.data.data
                    });
                }
            });
        },
        getclassification: function() {
            var t = this;
            a._getNetWork({
                showToastIn: !1,
                url: a.getNetAddresss("goods.category.search-goods-category"),
                success: function(a) {
                    var s = a.data;
                    1 == s.result && t.setData({
                        classification1: s.data
                    });
                }
            });
        },
        getname: function() {
            var t = this;
            a._getNetWork({
                showToastIn: !1,
                url: a.getNetAddresss("goods.filtering.index"),
                success: function(a) {
                    var s = a.data;
                    if (1 == s.result) {
                        for (var e = s.data, i = 0; i < e.length; i++) for (var n = 0; n < e[i].value.length; n++) t.data.filterId.includes(e[i].value[n].id) ? e[i].value[n].record = 2 : e[i].value[n].record = 1;
                        t.setData({
                            tagname: e
                        });
                    }
                }
            });
        },
        onClose: function() {
            this.setData({
                showPop: !1
            }), this.triggerEvent("clone");
        },
        onChangeGoodScreenAll: function(t) {
            this.setData({
                goodScreenAll: t.detail
            });
        },
        inpTop: function(t) {
            console.log(t, "ddddddddddd"), this.setData({
                top: t.detail
            });
        },
        inpMini: function(t) {
            this.setData({
                mini: t.detail
            });
        },
        onChange: function(t) {
            this.setData({
                activeName: t.detail
            });
        },
        changetype: function(t) {
            var a = t.currentTarget.dataset.key;
            switch (this.setData({
                select: a
            }), this.resetselect(), a) {
              case 0:
                this.setData({
                    show1: !0
                });
                break;

              case 1:
                this.setData({
                    show2: !0
                });
                break;

              case 2:
                this.setData({
                    show3: !0
                });
                break;

              case 3:
                this.setData({
                    show4: !0
                });
            }
        },
        resetselect: function() {
            this.setData({
                show1: !1,
                show2: !1,
                show3: !1,
                show4: !1
            });
        },
        screenbrand: function(t) {
            var a = t.currentTarget.dataset.id;
            this.setData({
                brandId: a
            }), this.cloneModel();
        },
        classificationtype: function(t) {
            var a = t.currentTarget.dataset.id;
            this.setData({
                classification2: [],
                typestring: a
            }), this.data.classificationId != a ? (this.setData({
                classificationId: a
            }), this.setData({
                classificationId1: null,
                classificationId2: null
            })) : this.setData({
                classificationId: null
            });
        },
        classificationtype1: function(t) {
            var a = t.currentTarget.dataset.id, s = t.currentTarget.dataset.key, e = t.currentTarget.dataset.val, i = t.currentTarget.dataset.parentIndex;
            this.setData({
                typestring: a,
                classificationParentIndex: i
            }), this.data.classificationId1 == a ? this.setData({
                classificationId1: null,
                classShowName: "",
                classShowind: ""
            }) : this.setData({
                classificationId1: a,
                classShowName: e.name,
                classShowind: s
            }), this.setData({
                classificationId2: null
            });
        },
        classificationtype2: function(t) {
            var a = t.currentTarget.dataset.id, s = t.currentTarget.dataset.key, e = t.currentTarget.dataset.val;
            this.data.typestring == a ? this.setData({
                typestring: null
            }) : this.setData({
                typestring: a
            }), this.data.classificationId2 == a ? this.setData({
                classificationId2: null,
                classShowName: "",
                classShowind: ""
            }) : this.setData({
                classificationId2: a,
                classShowName: e.name,
                classShowind: s
            }), console.log("ddddddddd", this.data.classShowName, this.data.classShowind);
        },
        selectattr: function(a) {
            var s = a.currentTarget.dataset.key;
            switch (console.log(s), s) {
              case 0:
                this.findstr("is_recommand", s);
                break;

              case 1:
                this.findstr("is_new", s);
                break;

              case 2:
                this.findstr("is_hot", s);
                break;

              case 3:
                this.findstr("is_discount", s);
                break;

              case 4:
                this.findstr("limit_buy", s);
            }
            this.data.attr[s].show ? this.setData(t({}, "attr[" + s + "].show", !1)) : this.setData(t({}, "attr[" + s + "].show", !0));
        },
        findstr: function(t, a) {
            var s = this.data.attrstr.indexOf(t);
            if (s + 1) {
                var e = this.data.attrstr;
                e.splice(s, 1), this.setData({
                    attrstr: e
                });
            } else {
                var i = this.data.attrstr;
                i.push(t), this.setData({
                    attrstr: i
                });
            }
            var n = this.data.attrkey.indexOf(a);
            if (n + 1) {
                var r = this.data.attrkey;
                r.splice(n, 1), this.setData({
                    attrkey: r
                });
            } else {
                var o = this.data.attrkey;
                o.push(a), this.setData({
                    attrkey: o
                });
            }
        },
        showtagname: function(t) {
            var a = t.currentTarget.dataset.key;
            a != this.data.showtagnamekey ? this.setData({
                showtagnamekey: a
            }) : this.setData({
                showtagnamekey: null
            });
        },
        selectname: function(a) {
            var s = a.currentTarget.dataset.id, e = a.currentTarget.dataset.key, i = a.currentTarget.dataset.keyx;
            if (1 == this.data.tagname[e].value[i].record) {
                if (this.data.filterId.includes(s)) return;
                var n = this.data.filterId;
                n.push(s), this.setData({
                    filterId: n
                }), this.setData(t({}, "tagname.[" + e + "].value[" + i + "].record", 2));
            } else {
                var r = this.data.filterId.indexOf(s), o = this.data.filterId;
                o.splice(r, 1), this.setData({
                    filterId: o
                }), this.setData(t({}, "tagname.[" + e + "].value[" + i + "].record", 1));
            }
        },
        resetnames: function() {
            this.setData({
                showtagnamekey: null,
                brandId: "",
                attrstr: [],
                filterId: [],
                typestring: "",
                attr: [ {
                    name: "推荐商品",
                    show: !0
                }, {
                    name: "新品上市",
                    show: !0
                }, {
                    name: "热卖商品",
                    show: !0
                }, {
                    name: "促销商品",
                    show: !0
                }, {
                    name: "限时抢购",
                    show: !0
                } ],
                classificationkey: null,
                classificationkey1: null,
                classificationkey2: null
            });
            for (var a = 0; a < this.data.tagname.length; a++) for (var s = 0; s < this.data.tagname[a].value.length; s++) 2 == this.data.tagname[a].value[s].record && this.setData(t({}, "tagname.[" + a + "].value[" + s + "].record", 1));
            this.cloneModel();
        },
        screen: function() {
            this.cloneModel();
        },
        cloneModel: function() {
            var t = {
                brandId: this.data.brandId,
                attrstr: this.data.attrstr.toString(),
                filterId: this.data.filterId.toString(),
                typestring: this.data.typestring,
                top: this.data.top,
                mini: this.data.mini
            };
            console.log("ddddddddddd", t), this.triggerEvent("confirm", t), this.onClose();
        }
    }
});